home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WINSRC20.ZIP / WINFRACT.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  44KB  |  1,195 lines

  1. /****************************************************************************
  2.  
  3.  
  4.     PROGRAM: winfract.c
  5.  
  6.     PURPOSE: Windows-specific main-driver code for Fractint for Windows
  7.              (look in MAINFRAC.C for the non-windows-specific code)
  8.  
  9.     Copyright (C) 1990 The Stone Soup Group.  Fractint for Windows 
  10.     may be freely copied and distributed, but may not be sold.
  11.     
  12.     We are, of course, copyrighting the code we wrote to implement
  13.     Fractint-for-Windows, and not the routines we lifted directly
  14.     or indirectly from Microsoft's Windows 3.0 Software Development Kit.
  15.  
  16. ****************************************************************************/
  17.  
  18. #include "windows.h"
  19. #include "winfract.h"
  20. #include "fractype.h"
  21. #include "fractint.h"
  22. #include "select.h"
  23. #include <math.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <search.h>
  27. #include <string.h>
  28. #include <time.h>
  29.  
  30. LPSTR win_lpCmdLine;
  31.  
  32. HANDLE hInst;
  33.  
  34. HWND hwnd;                               /* handle to main window */
  35. HWND hWndCopy;                 /* Copy of hWnd */
  36.  
  37. #define PALETTESIZE 256               /* dull-normal VGA                    */
  38. HANDLE hpal;                          /* palette handle                     */
  39. PAINTSTRUCT ps;                       /* paint structure                    */
  40. HDC hDC;                              /* handle to device context           */
  41. HDC hMemoryDC;                        /* handle to memory device context    */
  42. BITMAP Bitmap;                        /* bitmap structure                   */
  43.  
  44. HANDLE  hPal;          /* Handle to the application's logical palette  */
  45. HANDLE  hLogPal;       /* Temporary Handle */
  46. LPLOGPALETTE pLogPal;  /* pointer to tha application's logical palette */
  47. int     iNumColors;    /* Number of colors supported by device           */
  48. int     iRasterCaps;   /* Raster capabilities                           */
  49. int     iPalSize;      /* Size of Physical palette                       */
  50.  
  51. BOOL    win_systempaletteused = FALSE;    /* flag system palette set */
  52. extern int win_syscolorindex[21];
  53. extern DWORD win_syscolorold[21];
  54. extern DWORD win_syscolornew[21];
  55.  
  56. #define EXE_NAME_MAX_SIZE  128
  57.  
  58. BOOL       bHelp = FALSE;      /* Help mode flag; TRUE = "ON"*/
  59. HCURSOR    hHelpCursor;        /* Cursor displayed when in help mode*/
  60. char       szHelpFileName[EXE_NAME_MAX_SIZE+1];    /* Help file name*/
  61.  
  62. void MakeHelpPathName(char*);  /* Function deriving help file path */
  63.  
  64. unsigned char far win_dacbox[256][3];
  65. extern unsigned char dacbox[256][3];
  66.  
  67. BOOL bTrack = FALSE;                  /* TRUE if user is selecting a region */
  68. BOOL zoomflag = FALSE;                /* TRUE is a zoom-box selected */
  69. RECT Rect;
  70.  
  71. int Shape = SL_BLOCK;            /* shape to use for the selection rectangle */
  72.  
  73. /* pointers to various dialog-box routines */
  74. FARPROC lpProcAbout;
  75. FARPROC lpOpenDlg;
  76. FARPROC lpSelectFractal;
  77. FARPROC lpSelectFracParams;
  78. FARPROC lpSelectImage;
  79. FARPROC lpSelectDoodads;
  80. FARPROC lpSelectCycle;
  81. FARPROC lpSaveAsDlg;
  82. FARPROC lpProcStatus;
  83. FARPROC lpSelect3D;
  84. FARPROC lpSelect3DPlanar;
  85. FARPROC lpSelect3DSpherical;
  86.  
  87. extern unsigned char readname[], FileName[], FormFileName[];
  88. extern unsigned char DialogTitle[], DefSpec[], DefExt[];
  89.  
  90. HBITMAP hBitmap, oldBitmap, oldoldbitmap;              /* working bitmaps */
  91.  
  92. HANDLE hDibInfo;        /* handle to the Device-independent bitmap */
  93. LPBITMAPINFO pDibInfo;        /* pointer to the DIB info */
  94. int far *palette_values;    /* pointer to palette values */
  95. HANDLE hpixels;            /* handle to the DIB pixels */
  96. unsigned char huge *pixels;    /* the device-independent bitmap  pixels */
  97. extern int bytes_per_pixelline;    /* pixels/line / pixels/byte */
  98.  
  99. int last_written_y = -2;        /* last line written */
  100. int screen_to_be_cleared = 1;    /* flag that the screen is to be cleared */
  101. int time_to_act = 0;        /* time to take some sort of action? */
  102. int time_to_restart = 0;        /* time to restart?  */
  103. int time_to_reinit = 0;         /* time to reinitialize?  */
  104. int time_to_quit = 0;           /* time to quit? */
  105. int time_to_save = 0;        /* time to save the file? */
  106. int time_to_print = 0;        /* time to print the file? */
  107. int time_to_load = 0;        /* time to load a new file? */
  108. int time_to_cycle = 0;          /* time to begin color-cycling? */
  109.  
  110. int win_3dspherical = 0;          /* spherical 3D? */
  111. int win_display3d, win_overlay3d; /* 3D flags */
  112.  
  113. extern int win_cycledir, win_cyclerand;
  114.  
  115. extern int calc_status;
  116.  
  117. int xdots, ydots, colors, maxiter;
  118. int ytop, ybottom, xleft, xright;
  119. int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
  120. int win_xdots, win_ydots;
  121. extern int fractype;
  122. extern double param[4];
  123. extern double xxmin, xxmax, yymin, yymax, xx3rd, yy3rd;
  124. double jxxmin, jxxmax, jyymin, jyymax, jxx3rd, jyy3rd;
  125. extern int frommandel, bitshift, biomorph;
  126.  
  127. extern char str[255];
  128.  
  129. int cpu, fpu;            /* cpu, fpu flags */
  130.  
  131. extern int win_release;
  132.  
  133. char *win_choices[100];
  134. int win_numchoices, win_choicemade;
  135.  
  136. extern int onthelist[];
  137. extern int CountFractalList;
  138. extern int CurrentFractal;
  139. char FormNameChoices[41][21];
  140. char FormName[30];
  141. extern char    ifsfilename[];    /* IFS code file */
  142. extern char    ifs3dfilename[];  /* IFS 3D code file */
  143.  
  144. /****************************************************************************
  145.  
  146.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  147.  
  148.     PURPOSE: calls initialization function, processes message loop
  149.  
  150. ****************************************************************************/
  151.  
  152. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  153. HANDLE hInstance;
  154. HANDLE hPrevInstance;
  155. LPSTR lpCmdLine;
  156. int nCmdShow;
  157. {
  158.     int Return;
  159.  
  160.     win_lpCmdLine = lpCmdLine;
  161.  
  162.     if (!hPrevInstance)
  163.         if (!InitApplication(hInstance))
  164.             return (FALSE);
  165.  
  166.     if (!InitInstance(hInstance, nCmdShow))
  167.         return (FALSE);
  168.  
  169.     fractint_main();            /* fire up the main Fractint code */
  170.     DestroyWindow(hWndCopy);    /* stop everything when it returns */
  171.     
  172.     return(0);                  /* we done when 'fractint_main' returns */
  173. }
  174.  
  175. /****************************************************************************
  176.  
  177.     FUNCTION: InitApplication(HANDLE)
  178.  
  179.     PURPOSE: Initializes window data and registers window class
  180.  
  181. ****************************************************************************/
  182.  
  183. BOOL InitApplication(hInstance)
  184. HANDLE hInstance;
  185. {
  186.     WNDCLASS  wc;
  187.  
  188.     wc.style = CS_VREDRAW | CS_HREDRAW;
  189.     wc.lpfnWndProc = MainWndProc;
  190.     wc.cbClsExtra = 0;
  191.     wc.cbWndExtra = 0;
  192.     wc.hInstance = hInstance;
  193.     wc.hIcon = LoadIcon(hInstance, "FracIcon");
  194.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  195.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  196.     wc.lpszMenuName =  "WinFracMenu";
  197.     wc.lpszClassName = "FractintForWindowsV0010";
  198.  
  199.     return (RegisterClass(&wc));
  200. }
  201.  
  202.  
  203. /****************************************************************************
  204.  
  205.     FUNCTION:  InitInstance(HANDLE, int)
  206.  
  207.     PURPOSE:  Saves instance handle and creates main window
  208.  
  209. ****************************************************************************/
  210. BOOL InitInstance(hInstance, nCmdShow)
  211.     HANDLE          hInstance;
  212.     int             nCmdShow;
  213. {
  214.     DWORD WinFlags;
  215.     WORD  DeviceCaps;
  216.     int iLoop, jLoop;
  217.     DWORD ThisColor;
  218.     
  219.     float temp;
  220.     char tempname[40];
  221.  
  222.     /* so, what kind of a computer are we on, anyway? */
  223.     WinFlags = GetWinFlags();
  224.     cpu = 88;                             /* determine the CPU type */
  225.     if (WinFlags & WF_CPU186) cpu = 186;
  226.     if (WinFlags & WF_CPU286) cpu = 286;
  227.     if (WinFlags & WF_CPU386) cpu = 386;
  228.     if (WinFlags & WF_CPU486) cpu = 386;
  229.     fpu = 0;                              /* determine the FPU type */
  230.     if (WinFlags & WF_80x87)  fpu = 87;
  231.     if (WinFlags & WF_CPU486) fpu = 387;
  232.  
  233.     hInst = hInstance;
  234.  
  235.     temp = win_release / 100.0;
  236.     sprintf(tempname,"Fractint for Windows - Vers %5.2f", temp);
  237.  
  238.     hwnd = CreateWindow(
  239.         "FractintForWindowsV0010",
  240.         tempname,
  241.         WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
  242.         160, 1